package cn.iocoder.yudao.module.game.service.customerService;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.game.controller.admin.customerService.vo.*;
import cn.iocoder.yudao.module.game.dal.dataobject.customerService.CustomerServiceDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.game.dal.mysql.customerService.CustomerServiceMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.game.enums.ErrorCodeConstants.*;

/**
 * 客服人员 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class CustomerServiceServiceImpl implements CustomerServiceService {

    @Resource
    private CustomerServiceMapper customerServiceMapper;

    @Override
    public Long createCustomerService(CustomerServiceSaveReqVO createReqVO) {
        // 插入
        CustomerServiceDO customerService = BeanUtils.toBean(createReqVO, CustomerServiceDO.class);
        customerServiceMapper.insert(customerService);
        // 返回
        return customerService.getId();
    }

    @Override
    public void updateCustomerService(CustomerServiceSaveReqVO updateReqVO) {
        // 校验存在
        validateCustomerServiceExists(updateReqVO.getId());
        // 更新
        CustomerServiceDO updateObj = BeanUtils.toBean(updateReqVO, CustomerServiceDO.class);
        customerServiceMapper.updateById(updateObj);
    }

    @Override
    public void deleteCustomerService(Long id) {
        // 校验存在
        validateCustomerServiceExists(id);
        // 删除
        customerServiceMapper.deleteById(id);
    }

    private void validateCustomerServiceExists(Long id) {
        if (customerServiceMapper.selectById(id) == null) {
            throw exception(CUSTOMER_SERVICE_NOT_EXISTS);
        }
    }

    @Override
    public CustomerServiceDO getCustomerService(Long id) {
        return customerServiceMapper.selectById(id);
    }

    @Override
    public PageResult<CustomerServiceDO> getCustomerServicePage(CustomerServicePageReqVO pageReqVO) {
        return customerServiceMapper.selectPage(pageReqVO);
    }

}